<?php
/**
 * PHP Framework Seo Friendly Uri class
 *
 * @author Andrew <andrew@vitche.com>
 * @author Frozen Rain <frozenrain@mail.ru>
 **/
class FriendlyUri {

    public static function buildFriendlyString($value) {

        $matches = array();
        preg_match_all("/[0-9а-яА-Яa-zA-Z]+/u", $value, $matches);
        if (count($matches)) {
            $value = '';
            $matches = array_pop($matches);
            foreach ($matches as $item) {

                $value .= $item . "+";

                // Do not allow too long friendly URIs to appear
                if (64 < strlen(mb_convert_encoding($value, "ASCII"))) {
                    break;
                }
            }

            $value = trim($value, "+");
        }

        return $value;
    }

    public static function buildReadableString($value) {
        $arAtoms = explode("/", $value);
        $nonCanonicalName = $arAtoms[count($arAtoms) - 2];
        $nonCanonicalName = str_replace("-", " ", $nonCanonicalName);
        $nonCanonicalName = ucwords($nonCanonicalName);

        return NamingConventionMapper::mapPhrase($nonCanonicalName);
    }
}
?>